<template>
  <view>
    <view class="search-box">
      <my-search @click.native="handleClick"></my-search>
    </view>
    <!-- 轮播图 -->
    <swiper indicator-dots autoplay :duration="1000" :interval="3000" circular>
      <swiper-item v-for="(item,index) in swiperList" :key='index'>
        <navigator :url="`/subpkg/goods_detail/goods_detail?id=${item.goods_id}`">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 导航栏 -->
    <view class="nav-list">
      <view class="nav-item" v-for="item in navList" :key="item.goods_id">
        <image :src="item.image_src" class="nav-img" @click="navClicke(item)"></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <view class="floor-list">
      <!-- 楼层 item 项 -->
      <view class="floor-item" v-for="(item, i) in floorList" :key="i">
        <!-- 楼层标题 -->
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        <!-- 楼层图片区域 -->
        <view class="floor-img-box">
          <!-- 左侧大图片的盒子 -->
          <navigator class="left-img-box"
            :url="'/subpkg/goods_list/goods_list'+item.product_list[0].navigator_url.substr(item.product_list[0].navigator_url.indexOf('?'))">
            <image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}"
              mode="widthFix"></image>
          </navigator>
          <!-- 右侧 4 个小图片的盒子 -->

          <view class="right-img-box">
            <navigator
              :url="'/subpkg/goods_list/goods_list'+item2.navigator_url.substr(item2.navigator_url.indexOf('?'))"
              class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 !== 0">
              <image :src="item2.image_src" mode="widthFix" :style="{width: item2.image_width + 'rpx'}"></image>
            </navigator>
          </view>
        </view>


      </view>
    </view>
  </view>
  </view>
  </view>
  </view>
</template>

<script>
  import badge from '@/components/tabBar-badge.js'
  export default {
    name: 'home',
    mixins: [badge],
    data() {
      return {
        swiperList: [],
        navList: [], //导购数据
        floorList: [] //楼层数据
      };
    },
    onLoad() {
      this.getswiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods: {
      // 拿到轮播数据
      async getswiperList() {
        let {
          data: {
            message
          }
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        this.swiperList = message
        // console.log(this.swiperList)
      },
      //拿到导航数据
      async getNavList() {
        let {
          data: {
            meta: {
              status
            },
            message
          }
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (status !== 200) uni.$showMsg()
        this.navList = message
        // console.log("navList", this.navList)
      },
      //点击导航
      navClicke(item) {
        console.log(item)
        if (item.name == '分类') {
          uni.switchTab({
            url: '/pages/cate/cate'
          })
        }
      },
      async getFloorList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.floorList = res.message
        // console.log(this.floorList)
      },
      handleClick() {
        // console.log('ok')
        uni.navigateTo({
          url: '/subpkg/search/search'
        })
      }
    }
  }
</script>

<style lang="scss">
  * {
    margin: 0;
    padding: 0;
  }

  .swiper {
    height: 330rpx;
  }

  swiper-item,
  swiper-item image,
  swiper-item navigator {
    width: 100%;
    height: 100%;
  }

  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;

    .nav-img {
      width: 128rpx;
      height: 140rpx;
    }

  }

  .floor-title {
    height: 60rpx;
    width: 100%;
    display: flex;
  }

  .right-img-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }

  .floor-img-box {
    display: flex;
    padding-left: 10rpx;
  }

  .search-box {
    position: sticky;
    top: 0;
    z-index: 99999;
  }
</style>
